function getMaxSortedDistance(arr) {
    let max = arr[0];
    let min = arr[0];
    for (i = 1; i < arr.length; i++) {
        (arr[i] > max) && (max = arr[i]);
        (arr[i] < min) && (min = arr[i]);
    }
    let d = max - min;
    if (d === 0) {
        return 0;
    }
    let bucketNum = arr.length;
    const buckets = new Array(bucketNum);
    for (let i = 0; i < bucketNum; i++) {
        buckets[i] = new Bucket();
    }
    for (let i = 0; i < arr.length; i++) {
        const index = Math.floor((arr[i] - min) * (bucketNum - 1) / d);
        console.log(index);
        if (buckets[index].min === null || buckets[index].min > arr[i]) {
            buckets[index].min = arr[i];
        }
        if (buckets[index].max === null || buckets[index].max < arr[i]) {
            buckets[index].max = arr[i];
        }
    }
    console.log(buckets);
    let leftMax = buckets[0].max;
    let maxDistance = 0;
    for (let i = 0; i < buckets.length; i++) {
        if (buckets[i].min === null) {
            continue;
        }
        if (buckets[i].min - leftMax > maxDistance) {
            maxDistance = buckets[i].min - leftMax;
        }
        leftMax = buckets[i].max;
    }
    return maxDistance;
}
class Bucket {
    min = null;
    max = null;
}

const arr = [2,6,3,4,5,10,9];
const res = getMaxSortedDistance(arr);
console.log(res);